
<html lang="en">
<head>
    @include('Admin.header')
    <style>
        .layui-form-label{

        }
    </style>
</head>
<body>
<div class="wrapper layui-container">
    <div class="page-content layui-row ">
        <div class="content layui-col-xs11 layui-col-xs-offset1">
            <form class="layui-form" id="form">
                <div class="layui-form-item">
                    <label for="account" class="layui-form-label">
                        <span class="x-red"> * </span>账号
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="account" name="account" required="" lay-verify="account"
                               autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        4到12个字符
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="nickname" class="layui-form-label">
                        <span class="x-red"> * </span>昵称
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="nickname" name="nickname" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">分配角色</label>
                    <div class="layui-input-inline">
                        <select name="role_id" >
                            <option value="">暂不分配</option>
                            @foreach ($roles as $k=>$v)
                            <option value="{{$k}}">{{$v}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="password" class="layui-form-label">
                        <span class="x-red"> * </span>密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="password" name="password" required="" lay-verify="password"
                               autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        6到16个字符
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="repassword" class="layui-form-label">
                        <span class="x-red"> * </span>确认密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="repassword" name="repassword" required="" lay-verify="repassword"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                {{ csrf_field() }}
                <div class="layui-form-item">
                    <label for="" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit>
                        增加
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>

    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(add)', function(data){
            $.ajax({
                dataType:'json',
                type: 'post',
                url: '{{url("Admin/System/administrator/do")}}',
                data: $('#form').serialize(),
                success: function(data){
                    if(1 == data){
                        layer.msg('增加成功!', {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            parent.layer.closeAll();
                        });
                    }else if(2 == data){
                        layer.msg('账号已存在!');
                    }else{
                        layer.msg('增加失败!');
                    }
                }
            });
            return false;
        });

        form.verify({
            account: function(value, item){
                if(!value){
                    return '账号不能为空';
                }
                if(value.length < 4 || value.length > 12){
                    return '账号4-12位';
                }
                var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
                if(reg.test(value)){
                    return '账号不得包含中文';
                }
            }

            ,password: function(value, item){
                if(!value){
                    return '密码不能为空';
                }
                if(value.length < 6 || value.length > 16){
                    return '密码6-16位';
                }
            }
            ,repassword:function(value, item){
                if(value !== $('#password').val()){
                    return '两次密码不一致';
                }
            }
        });
    });
</script>
</body>
</html>